package org.liuyunfeng.web;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author: TanJingyu
 * @create: 2022-04-01 16:03
 **/
@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private MongoTemplate mongoTemplate26;

    @GetMapping
    public String hello(HttpServletRequest request) {
        return "hello";
    }

    @GetMapping("/mongo")
    public Object hello() {
        return mongoTemplate.findById(66783067, MongoDTO.class);
    }


    @GetMapping("/mongo26")
    public Object hello26() {
        return mongoTemplate26.getCollectionNames();
    }


    @Document(collation = "zb_content_document")
    @Getter
    @Setter
    public static class MongoDTO {
        private String title;
        private Date date;
    }
}

    